package com.borqsprocessmanager.view;

import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.borqsprocessmanager.ConfigParams;
import com.borqsprocessmanager.R;
import com.umeng.fb.UMFeedbackService;

public class MessagePopWindow implements OnTouchListener, OnClickListener {

    private Activity mActivity;
    private PopupWindow mPopupWindow;
    private boolean isShow = false;

    public void showMessagePop(Activity activity) {
        mActivity = activity;
        LayoutInflater mLayoutInflater = (LayoutInflater) activity
                .getSystemService(activity.LAYOUT_INFLATER_SERVICE);
        View popupwindwow = mLayoutInflater.inflate(R.layout.message_dialog,
                null);
        popupwindwow.setOnTouchListener(this);
        TextView massageText = (TextView) popupwindwow
                .findViewById(R.id.massage_text);
        if (!ConfigParams.MESSAGE.equals("")) {
            massageText.setText(ConfigParams.MESSAGE);
        }

        Button feedback = (Button) popupwindwow
                .findViewById(R.id.massage_feedback);
        feedback.setOnClickListener(this);

        mPopupWindow = new PopupWindow(popupwindwow, LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT) {
        };
        mPopupWindow.showAtLocation(activity.findViewById(R.id.main_layout),
                Gravity.CENTER, 0, 0);
        mPopupWindow.setAnimationStyle(android.R.style.Animation_Toast);
        mPopupWindow.update();
        isShow = true;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        dissmissDialog();
        return false;
    }

    @Override
    public void onClick(View v) {
        UMFeedbackService.openUmengFeedbackSDK(mActivity);
    }

    public void dissmissDialog() {
        mPopupWindow.dismiss();
        mPopupWindow = null;
        isShow = false;
    }

    public boolean isShow() {
        return isShow;

    }

}
